﻿using System;

namespace Eamon.MeituanDotnetSDK.@enum
{
    /// <summary>
    /// SDK本地错误码
    /// </summary>
    public enum SdkErrorEnum
    {
        MISS_PARAM_ERROR,
        REQUEST_FAILED_ERROR,
        PARSE_RESPONSE_ERROR,
        VERIFY_PARAM_ERROR,
        MISS_APPAUTHTOKEN_ERROR,
        HTTPCLIENT_ERROR,
        SIGNNER_UTIL_ERROR
    }

    public static class SdkErrorEnumExtensions
    {
        public static string GetCode(this SdkErrorEnum error)
        {
            return error switch
            {
                SdkErrorEnum.MISS_PARAM_ERROR => "SDK_PARAM_ERROR",
                SdkErrorEnum.REQUEST_FAILED_ERROR => "SDK_REQUEST_FAILED_ERROR",
                SdkErrorEnum.PARSE_RESPONSE_ERROR => "SDK_PARSE_RESPONSE_ERROR",
                SdkErrorEnum.VERIFY_PARAM_ERROR => "SDK_VERIFY_PARAM_ERROR",
                SdkErrorEnum.MISS_APPAUTHTOKEN_ERROR => "SDK_MISS_APPAUTHTOKEN_ERROR",
                SdkErrorEnum.HTTPCLIENT_ERROR => "SDK_HTTPCLIENT_ERROR",
                SdkErrorEnum.SIGNNER_UTIL_ERROR => "SDK_SIGNNER_UTIL_ERROR",
                _ => throw new ArgumentOutOfRangeException(nameof(error), error, null)
            };
        }

        public static string GetMsg(this SdkErrorEnum error)
        {
            return error switch
            {
                SdkErrorEnum.MISS_PARAM_ERROR => "缺少必要的请求参数。",
                SdkErrorEnum.REQUEST_FAILED_ERROR => "SDK执行请求异常。",
                SdkErrorEnum.PARSE_RESPONSE_ERROR => "返回值解析异常。",
                SdkErrorEnum.VERIFY_PARAM_ERROR => "参数校验异常。",
                SdkErrorEnum.MISS_APPAUTHTOKEN_ERROR => "缺少appAuthToken。",
                SdkErrorEnum.HTTPCLIENT_ERROR => "SDK网络请求工具内部错误。",
                SdkErrorEnum.SIGNNER_UTIL_ERROR => "计算签名时发生异常。",
                _ => throw new ArgumentOutOfRangeException(nameof(error), error, null)
            };
        }
    }
}